<?php
require('config.php');
		$user_id=$_REQUEST['user_id'];
        $user_name=$_REQUEST['user_name'];
        $user_mobile=$_REQUEST['user_mobile'];
        $address1=$_REQUEST['address1'];
        $address2=$_REQUEST['address2'];
        $address3=$_REQUEST['address3'];
        $address4=$_REQUEST['address4'];
        $jiedao=$_REQUEST['jiedao'];
        $time=date('Y-m-d H:i:s');

        $sql="select * from `".$oto."_areas` where `areaName` LIKE '%$address1%' and areaFlag='1' and parentId='0'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$sheng_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		$sql="select * from `".$oto."_areas` where `areaName` LIKE '%$address2%' and areaFlag='1' and parentId!='0'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$shi_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		$sql="select * from `".$oto."_areas` where `areaName` LIKE '%$address3%' and areaFlag='1' and parentId!='0'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$qu_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		$sql="select * from `".$oto."_communitys` where `communityName` LIKE '%$address4%' and communityFlag='1'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$shequ_info[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(isset($sheng_info)) $sheng_id=$sheng_info[0]['areaId'];
		else $sheng_id=0;
		if(isset($shi_info)) $shi_id=$shi_info[0]['areaId'];
		else $shi_id=0;
		if(isset($qu_info)) $qu_id=$qu_info[0]['areaId'];
		else $qu_id=0;
		if(isset($shequ_info)) $shequ_id=$shequ_info[0]['communityId'];
		else $shequ_id=0;
		$address1=$sheng_id;
		$address2=$shi_id;
		$address3=$qu_id;
		$address4=$shequ_id;

		$sql="select * from `".$oto."_user_address` where `userId`='".$user_id."'";
		$result=$db->query($sql);
		while($row=$result->fetch_assoc()){
			$user_address[]=$row;//将取得的所有数据赋值给person_info数组
		}
		if(!isset($user_address))
		{
			$sql="INSERT INTO ".$oto."_user_address (`userId`,`userName`,`userPhone`,`areaId1`,`areaId2`,`areaId3`,`communityId`,`address`,`isDefault`,`createTime`) VALUES ('$user_id','$user_name','$user_mobile','$address1','$address2','$address3','$address4','$jiedao','1','$time')";
            $result=$db->query($sql);
		}
		else
		{
			$sql="INSERT INTO ".$oto."_user_address (`userId`,`userName`,`userPhone`,`areaId1`,`areaId2`,`areaId3`,`communityId`,`address`,`isDefault`,`createTime`) VALUES ('$user_id','$user_name','$user_mobile','$address1','$address2','$address3','$address4','$jiedao','0','$time')";
            $result=$db->query($sql);
		}
		echo json_encode($result);
?>
